package com.hxzy.module.store.api.fallback;

import com.github.pagehelper.PageInfo;
import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.module.store.api.store.StoreFeignApi;
import com.hxzy.module.store.api.store.req.StoreReq;
import com.hxzy.module.store.api.store.resp.StoreAccountResp;
import com.hxzy.module.store.api.store.resp.StoreResp;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * @Author wy
 * @Description feign调用失败，回调
 * @Date 2024/1/27 9:32
 * @Version 1.0
 */
@Log4j2
@Component
public class StoreFeignApiFallbackFactory implements FallbackFactory<StoreFeignApi> {

    @Override
    public StoreFeignApi create(Throwable throwable) {
        log.error(throwable);
        return new StoreFeignApiImpl();
    }

    /**
     * 内部类实现回调方法
     */
     class StoreFeignApiImpl implements StoreFeignApi{

        @Override
        public R<PageInfo<StoreResp>> storeList(StoreReq req) {
            return R.failed(ResultCode.DEMOTION);
        }

        @Override
        public R<StoreResp> findByStoreId(Long storeId) {
            return R.failed(ResultCode.DEMOTION);
        }

        @Override
        public R<StoreAccountResp> storeAccountFindByAccount(String account) {
            return R.failed(ResultCode.DEMOTION);
        }
    }
}
